<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>多级对象解构</title>
</head>

<body>
  <script>
    // ============================== 多级对象解构 ==============================
    // 练习 1：要求把所有家庭成员解构出来
    const pig = {
      name: '佩奇',
      family: {
        mother: '猪妈妈',
        father: '猪爸爸',
        sister: '乔治'
      },
      other: {
        mother: '猪1',
        father: '猪2',
        sister: '乔3'
      },
      age: 6
    }

    const {name,age,family:{mother,father,sister},other:{mother:mother1,father:father1,sister:sister1}} = pig
    console.log(name,age,mother,father,sister,mother1,father1,sister1) //佩奇 6 猪妈妈 猪爸爸 乔治 猪1 猪2 乔3
    

    // 练习2：要求把所有家庭成员解构出来
    // const arr = [
    //   {
    //     name: '佩奇',
    //     family: {
    //       mother: '猪妈妈',
    //       father: '猪爸爸',
    //       sister: '乔治'
    //     },
    //     age: 6
    //   }
    // ]
    // const [{name,age,family:{mother,father,sister}}] = arr
    // console.log(name,age,mother,father,sister) //佩奇 6 猪妈妈 猪爸爸 乔治
    
  </script>
</body>

</html>